package com.pei.controller;

import com.pei.pojo.Order;
import com.pei.pojo.Product;
import com.pei.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Set;

@Controller
public class OrderController {
    @RequestMapping("/showOrders")
    public void showOrders(User user){
        List<Order> orders = user.getOrders();
        List<String> addressList = user.getAddress();
        for (int i = 0; i < orders.size(); i++) {
            Order order = orders.get(i);
            System.out.println("订单ID"+orders.get(i).getOrderId());
            System.out.println("订单配送地址:"+addressList.get(i));
        }
    }

    @RequestMapping("/orderInfo")
    public void getOrderInfo(Order order){
        String orderId = order.getOrderId();
        HashMap<String, Product> orderInfo = order.getProductInfo();
        Set<String> keys = orderInfo.keySet();
        System.out.println("订单id"+orderId);

        for(String key : keys){
            Product product = orderInfo.get(key);
            String proId = product.getProId();
            String proName = product.getProName();
            System.out.println(key+"类"+"商品id"+proId+"商品名称"+proName);
        }
    }
}
